# sparecap.mod    
# by Yu Liu, 07/04/2001.
# Arc-flow model for spare capacity allocaiton

set FAILS := 1..MaxEdge;
param F {FAILS, LINKS} binary default 0;
# need to be declared somewhere
# for link, node, or arbitrary failure
param U {FLOWS, FAILS} binary default 0;
param T {FLOWS, LINKS} binary default 0;
# can be calculate from F and P

var Q {FLOWS, LINKS} binary default 0;
var G {LINKS, FAILS} default 0;
var s {LINKS} default 0;

minimize s_cost: (sum {(i1,i2) in LINKS} c[i1,i2]*s[i1,i2])/2;

s.t. cap_aggrS {(i1,i2) in LINKS, k in FAILS}:
  s[i1,i2] >= G[i1,i2,k];
# s >= G  or s = max G

s.t. spm_comp {(i1,i2) in LINKS, k in FAILS}:
  G[i1,i2,k] = sum{(r1,r2) in FLOWS} 
     M[r1,r2] * (Q[r1,r2,i1,i2] * U[r1,r2,k]);
# G = Q^T M U

s.t. fail_disj {(r1,r2) in FLOWS,(i1,i2) in LINKS}:
  T[r1,r2,i1,i2] + Q[r1,r2,i1,i2] <= 1;
# T + Q <= 1

s.t. mass_baS {(r1,r2) in FLOWS, n1 in NODES}:
  sum {(i1,i2) in LINKS} Q[r1,r2,i1,i2]*B[n1,i1,i2]=D[r1,r2,n1];
# Q B^T = D

s.t. backup_sym {(r1,r2) in FLOWS, (i1,i2) in LINKS:i1<i2}:
  Q[r1,r2,i1,i2] = Q[r2,r1,i2,i1];
# Q is symatric for symetric flows

problem find_spare:
 s_cost, cap_aggrS, spm_comp, fail_disj, mass_baS, backup_sym, Q, G, s;



